<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>账号购买</title>
    <link rel="stylesheet" href="./src/bootstrap/css/bootstrap.min.css">
    <!-- <style>
        textarea { min-height: 320px; }
        pre { padding: 6px 12px; min-height:400px; }
        .string { color: #92278f; }
        .number { color: #25aae2; }
        .boolean { color: #f0ad4e; }
        .null { color: #d9534f; }
        .key { color: #4cae4c; }
    </style> -->
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-md-6 col-md-offset-3">
            <h3>账号购买</h3>
            <hr>
        </div>
        <div class="col-md-6 col-md-offset-3">
            <div class="jumbotron">
                <h1>ChatGPT</h1>
                <p>10元/个</p>
                <p>
                    <a class="btn btn-success btn-lg" onclick="buy()" href="#" role="button">购买</a>
                </p>
            </div>
            <br>
        </div>
    </div>
</div> 
</body>
<script src="./src/axios.min.js"></script>
<script src="./src/config.js"></script>
<script>

    // (function load() {
    //     const api_domain = localStorage.getItem('api_domain');
    //     if (api_domain) {
    //         document.getElementsByName('domain')[0].value = api_domain;
    //     }
    // })()

    var AppApi = window.AppApi;
    function buy () {

        const api_domain = "http://127.0.0.1:2020";

        var config = {
            method: 'post',
            url: api_domain + "/account/put",
            data: {},
            withCredentials: true,
            crossDomain: true,
            headers: {
                'Authorization': localStorage.getItem('token'),
            }, // 跨域需要关掉自定义header
        }
        
        curl(config, function ( dd ){
            var content = dd.data;
            console.log(content);
            alert(content.msg);
            if (content.code == 0) {
                alert(content.data.token);
            }
        });

    }

    // function save () {
    //     var domain = document.getElementsByName('domain')[0].value;
    //     var code = document.getElementsByName('code')[0].value;
    //     // localStorage.setItem('api_domain', domain);

    //     alert('保存成功');
    // }

    // 发送 CURL 请求
    function curl ( config , callback ) {
        axios(config).then(callback).catch(function (error) {
            console.log(error);
        });
    }

</script>
</html>